// 引入 Vue 和 Vue Router
import component from 'element-plus/es/components/tree-select/src/tree-select-option.mjs';
import { createApp } from 'vue';
import { createRouter, createWebHistory } from 'vue-router';



// 创建路由配置
const routes = [
    // ✅ 关键配置：根路径重定向到/login
    {
        path: '/',
        redirect: '/login' // 自动跳转
    },
    {
        path: '/login',
        name: 'Login',
        // component: () => import("@/views/login/index.vue")
        component: () => import('../views/login/index.vue')
    },
    {
        path: '/register',
        name: 'Register',
        component: () => import('../views/register/index.vue'),
    },
    {
        path: '/patient', // ✅ 相对路径，实际路径为 /register/patient
        name: 'Patient',
        component: () => import('../views/register/Role/patient.vue')
    },
    {
        path: '/doctor', // ✅ 相对路径，实际路径为 /register/doctor
        name: 'Doctor',
        component: () => import('../views/register/Role/doctor.vue')
    },
    {
        path: '/home',
        name: 'Home',
        component: () => import('../views/home/index.vue'),
        children: [
            // 个人信息管理
            {
                path: 'main',
                name: 'main',
                component: () => import('../views/home/main.vue'),
                meta: { roles: ['admin', 'doctor', 'patient'] }
            },
            // 个人信息管理
            {
                path: 'profile',
                name: 'Profile',
                
                component: () => import('../views/user/profile/index.vue'),
                meta: { roles: ['admin', 'doctor', 'patient'] }
            },
            {
                path: 'profileDoctor',
                name: 'profileDoctor',
                component: () => import('../views/user/profile/doctor/index.vue'),
                meta: { roles: ['admin', 'doctor', 'patient'] }
            },
            {
                path: 'profilePatient',
                name: 'profilePatient',
                
                component: () => import('../views/user/profile/patient/index.vue'),
                meta: { roles: ['admin', 'doctor', 'patient'] }
            },

            // 用户管理
            {
                path: 'user-manage',
                name: 'UserManage',
                component: () => import('../views/user/user-manage/patient.vue'),
                meta: { roles: ['admin'] },
            },
            // 医生
            {
                path: 'doctor-manage',
                name: 'doctorManage',
                component: () => import('../views/user/user-manage/doctor.vue'),
                meta: { roles: ['admin'] },
            },

            // 健康数据管理子路由
            {
                path: 'daily/upload',
                name: 'DailyUpload',
                component: () => import('../views/daily/upload/index.vue'),
                meta: { roles: ['admin', 'doctor', 'patient'] }
            },
            {
                path: 'daily/analysis',
                name: 'DailyAnalysis',
                component: () => import('../views/daily/analysis/index.vue'),
                meta: { roles: ['admin', 'doctor', 'patient'] }
            },
            {
                path: 'health/upload',
                name: 'HealthUpload',
                component: () => import('../views/health/upload/index.vue'),
                meta: { roles: ['admin', 'doctor', 'patient'] }
            },
            {
                path: 'health/analysis',
                name: 'HealthAnalysis',
                component: () => import('../views/health/analysis/index.vue'),
                meta: { roles: ['admin', 'doctor', 'patient'] }
            },

            // 医生建议（用户,）
            {
                path: 'medical-records-patient',
                name: 'MedicalRecordsPatient',
                component: () => import('../views/medical-records/patient/index.vue'),
                meta: { roles: ['admin', 'patient'] }
            },
            {
                path: 'consultation',
                name: 'Consultation',
                component: () => import('../views/consultation/index.vue'),
                meta: { roles: ['admin', 'patient'] }
            },
            {
                path: 'listDoctor',
                name: 'ListDoctor',
                component: () => import('../views/consultation/listDoctor.vue'),
                meta: { roles: ['admin', 'patient'] }
            },

            // 用户交流（医生）
            {
                path: 'communication',
                name: 'Communication',
                component: () => import('../views/communication/index.vue'),
                meta: { roles: ['doctor'] }
            },
            {
                path: 'medical-records-doctor',
                name: 'MedicalRecordsDoctor',
                component: () => import('../views/medical-records/doctor/index.vue'),
                meta: { roles: ['admin', 'patient'] }
            }
        ]
    }
];

// 创建路由实例
const router = createRouter({
    history: createWebHistory(),
    routes,
});

export default router;